/** ###################################################################
**     Filename  : CommandSystem.h
**     Project   : parking
**     Processor : MC9S12XS128MAL
**     Compiler  : CodeWarrior HCS12X C Compiler
**     Date/Time : 2013-2-23, 14:36
**     Contents  :
**         User source code
**
** ###################################################################*/

#ifndef __CommandSystem_H
#define __CommandSystem_H

/* MODULE CommandSystem */

#include "Types.h"

//start from one, should be attention when construct string
#define CS_MODE (1)
#define CS_DIRECTION (2)
#define CS_DISTANCE (3)
#define CS_SPEED (4)
#define CS_TRIG_MIN (5)
#define	CS_EXTENDED	(6)


#define  CS_EMPTY (0)
#define  CS_FORWARD (1)
#define  CS_BACKWARD (2)
#define  CS_AUTO_FORWARD (3)
#define  CS_AUTO_BACKWARD (4)
#define  CS_STOP (5)
#define  CS_MILESTONE (6)

		
		
		
		
		
#define	CS_PAUSE	0
#define	CS_MOVE	1
#define	CS_RESTART	2
#define	CS_LOOP	3
#define	CS_JUMP	4
#define	CS_STATUS	5
#define	CS_REQUIRE	6
#define	CS_SAVE	7
#define	CS_CONTINUE	8



#define	CS_STATUS_OFFSET	(100)

#define CS_FS	':'
#define CS_CS	'#'
#define CS_BUF_LEN	20

#define CS_OK	0
#define CS_BUSY	1
#define CS_WAIT_CS	3

#define CS_RUNNING 	0
//#define CS_SETTING 	1  //same as waiting
#define CS_WAITING	2

#define CS_MAX_COMMAND (26)


//#define CS_COMMAND_BUF_SIZE	(0x08)// 2^n will be fine, otherwise may go wrong
typedef struct CSCommand_t{
	S16 seq;
	S16 command;
	S16 value;	
} CSCommand;


extern U8 CSCommandState;
extern U8 CSNextCommandState;

void CSInit(void);
void CSIrqHandler(void);
void CSEntry(void);
void CSExec(CSCommand cmd);
void CSPause(void);
void CSMove(void);
void CSSendPCProcedure(U8 seq_from_one);
void CSRestart(void);
void CSJump(S16 seq);
void CSStatus(void);
void CSSave(void);
void CSContinue(void);
void CSLoop(S16 state);
void CSRequire(S16 seq);

/* END CommandSystem */

#endif

